//订单列表 0
//订单详情 2

//(function(){
define(function(require,exports,module){
	"require:nomunge,exports:nomunge,module:nomunge";
	
var firstLoadFlag=true;
var beginDate,endDate,beginAmt,endAmt,paymentId,erpOrderType,beginnums,endnums,orderstatusId,orderId,payStatus,pageSize=10,formIndex=0,backIndex=0,userId="",userName="",realName="",searchUserName="",_page=1,_pageSize=10,_totalCount=0;

    var wind_async=require('ddf_wind_async');
    var base=require('component-base');
    var history=require('component-history');
    require('component-page');
    var upload=require('component-upload');
    var defalueImgPath="../img/photos.png";
    var maxImgCount=5;//最多允许上传5张图片
    var currentMaxImgIndex=-1;//默认当前相片上传到-1这个位置（第一张是0这个位置）

    
    
    exports.setParams=function(_formIndex,_backIndex,_userId,_userName,_realName){
//    	initIndex=_formIndex;
    	formIndex=_formIndex;
    	backIndex=_backIndex;
    	userId=_userId;
    	userName=_userName;
    	realName=_realName;
    	
    };
    
    
/**
 * 查询订单列表
 */
//function loadOrderList() {
	
    exports.init=function(m){
    	history.addHis(this,arguments);//增加历史
    	firstLoadFlag=true;
    	window.$ddf_order = m;
		resetSearchParams();
		var htmlStr = "";
		htmlStr += '<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="javascript:void(0)" class="current">订单管理</a></div></div>';
		htmlStr += '<div class="container-fluid">';
		
		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span12">';
		htmlStr += '<div id="alert-tips0" ></div>';
		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title"><span class="icon"><i class="icon-search"></i></span><h5>搜索条件</h5><button type="button" class="label label-success toggle">缩放</button></div>  ';
		htmlStr += '<div class="widget-content nopadding">';
		htmlStr += '<form class="form-horizontal">';
		
		if(userId!=""){
			htmlStr += '<div class="row-fluid">';
			htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">会员账号：</label><div class="controls"><span class="inp_span" id="username">'+userName+'</span></div></div></div>';
			htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">会员姓名：</label><div class="controls"><span class="inp_span" id="realName">'+realName+'</span></div></div></div>';
			htmlStr += '</div>   ';
		}
		
		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">创建时间：</label><div class="controls"><input class="span4 m-wrap Wdate" type="text" id="obeginDate" onClick=WdatePicker({dateFmt:"yyyy-MM-dd",readOnly:false}) />&nbsp;&nbsp;至&nbsp;&nbsp;<input class="span4 m-wrap Wdate" type="text" id="oendDate" onClick=WdatePicker({dateFmt:"yyyy-MM-dd",readOnly:false}) /></div></div></div>';
		htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">支付方式：</label><div class="controls"><div class="btn-group"><button data-toggle="dropdown" class="btn dropdown-toggle"><span id="paymentName">请选择</span>&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu" id="paymentList"></ul></div>   <div class="btn-group" id="payStatusDiv" style="display:none;" ><button data-toggle="dropdown" class="btn dropdown-toggle"><span id="payStatusName">全部</span>&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu"><li><a href=javascript:$ddf_order.setPayStatus(0,"全部")>全部</a></li><li><a href=javascript:$ddf_order.setPayStatus(1,"已支付")>已支付</a></li><li><a href=javascript:$ddf_order.setPayStatus(2,"未支付")>未支付</a></li></ul></div> </div></div></div>';
		htmlStr += '</div>';
		htmlStr += '<div class="row-fluid"> ';
		htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">订单金额：</label><div class="controls"><input class="span4 m-wrap" type="text" id="beginAmt" />&nbsp;&nbsp;至&nbsp;&nbsp;<input class="span4 m-wrap" type="text" id="endAmt" /></div></div></div>';
		htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">订单类型：</label><div class="controls"><div class="btn-group"><button data-toggle="dropdown" class="btn dropdown-toggle"><span id="orderTypeName">请选择</span>&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu" id="orderTypeList"><li><a href="####">请选择</a></li><li><a href="####">网站订单</a></li><li><a href="####">手机订单</a></li><li><a href="####">终端订单</a></li></ul></div></div></div></div>';
		htmlStr += '</div> ';
		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">商品数量：</label><div class="controls"><input class="span4 m-wrap" type="text" id="beginnums" />&nbsp;&nbsp;至&nbsp;&nbsp;<input class="span4 m-wrap" type="text" id="endnums" /></div></div></div>';
		htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">订单状态：</label><div class="controls"><div class="btn-group"><button data-toggle="dropdown" class="btn dropdown-toggle"><span id="orderStatusName">请选择</span>&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu" id="orderStatusList"><li><a href="####">请选择</a></li><li><a href="####">待付款</a></li><li><a href="####">待发货</a></li><li><a href="####">待收货</a></li><li><a href="####">交易成功</a></li><li><a href="####">交易关闭</a></li></ul></div> </div> </div> </div>';
		htmlStr += '</div>   ';
		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">订单代码：</label><div class="controls"><input class="span8 m-wrap" type="text" id="orderId"/></div></div></div>';
		htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">客户名称：</label><div class="controls"><input class="span8 m-wrap" type="text" id="searchUserName"/></div></div></div>';

		htmlStr += '</div>';
		
		htmlStr += '<div class="form-actions">';
		htmlStr += '<button class="btn btn-primary" type="button" onClick="$ddf_order.searchOrder()">搜索</button>';
		htmlStr += ' <button class="btn btn-info" type="button" onClick="$ddf_order.resetSearchParams()">重置</button>';
		
		if(userId!=""){
			htmlStr += ' <button class="btn btn-info" type="button" onClick=$ddf_order.showDiv("content'+parseInt(backIndex)+'")>返回</button>';
		}
		
		htmlStr += '</div>        ';
		htmlStr += '</form>';
		htmlStr += '</div>';
		htmlStr += '</div> ';
		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
		htmlStr += '<h5>订单列表</h5>';
		htmlStr += '</div>';
		htmlStr += '<div class="widget-content nopadding dataTables_wrapper">';
		htmlStr += '<table class="table table-bordered data-table">';
		htmlStr += '<thead>';
		htmlStr += '<tr>';
		htmlStr += '<th>序号</th>';
		htmlStr += '<th>创建时间</th>';
		htmlStr += '<th>订单代码</th>';
		htmlStr += '<th>业务类型</th>';
		htmlStr += '<th>订单类型</th>';
		htmlStr += '<th>支付方式</th>';
		htmlStr += '<th>配送方式</th>';
		htmlStr += '<th>订单状态</th>';
		htmlStr += '<th>订单金额</th>';
		htmlStr += '<th>商品数量</th>';
		htmlStr += '<th>订单积分</th>';
		htmlStr += '<th>客户名</th>';
		htmlStr += '<th>操作</th>';
		htmlStr += '</tr>';
		htmlStr += '</thead>';
		htmlStr += '<tbody id="orderList">';
		htmlStr += '</tbody>';
		htmlStr += '</table>';
		htmlStr += '<div  id="footPageDivOrderList">';

		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '</div>  ';
		htmlStr += '</div>';
		htmlStr += '</div> ';
		htmlStr += '</div> ';

//		$("#content0").css("display", "block");
		showDiv("content"+formIndex);

		$("#content"+formIndex).html(htmlStr);
		

		getMyOrders(1,pageSize,beginDate,endDate,beginAmt,endAmt,paymentId,erpOrderType,beginnums,endnums,orderstatusId,orderId,payStatus,userId,searchUserName);

		getPaymentsList();
		
		getErpOrderTypesList();
		
		getOrderstatusList();
		

}



/**
 * 查询订单列表
 * @param pageNumber
 * @param username
 * @param mobile
 */
function getMyOrders(pageNumber,pageSize,beginDate,endDate,beginAmt,endAmt,paymentId,erpOrderType,beginnums,endnums,orderstatusId,orderId,payStatus,userId,searchUserName){
//	formIndex=initIndex;//还原传入的DIV下标
	var params={
			"page.pageNumber":pageNumber,
			"page.pageSize" : pageSize,
			"page.pageSize":pageSize,
			"beginDate":beginDate,
			"endDate":endDate,
			"beginAmt":beginAmt,
			"endAmt":endAmt,
			"paymentId":paymentId,
			"erpOrderType":erpOrderType,
			"beginnums":beginnums,
			"endnums":endnums,
			"orderstatusId":orderstatusId,
			"orderId":orderId,
			"payStatus":payStatus,
			"userId":userId,
			"userName":searchUserName
	        };
	

     base.showLoading();
	
//	DDF_AsyncRequest("POST",ddf.order.getMyOrders,params,'$ddf_order.getMyOrdersCallBack(data)');
	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.order.getMyOrders,params));
		
		getMyOrdersCallBack(data);
		
	}))().start();

	
}

/**
 * 查询订单列表_回调函数
 */
function getMyOrdersCallBack(data){
	if(data["code"]==1){

		var htmlStr = "";
		for (var i = 0; i < data["orderListData"].length; i++) {

			htmlStr += '<tr>';
			htmlStr += '<td>' +getSequence(data["pageNumber"],i+1) + '</td>';
			htmlStr += '<td>'+data["orderListData"][i]["OrderTime"]+'</td>';
			htmlStr += '<td>'+data["orderListData"][i]["OrderId"]+'</td>';
			htmlStr += '<td>'+data["orderListData"][i]["BusinessName"]+'</td>';
			htmlStr += '<td>'+data["orderListData"][i]["OrderTypeName"]+'</td>';
			htmlStr += '<td>'+data["orderListData"][i]["PayMentName"]+'</td>';
			htmlStr += '<td>'+data["orderListData"][i]["deliveryName"]+'</td>';
			htmlStr += '<td>'+data["orderListData"][i]["OrderStatusName"]+'</td>';
			htmlStr += '<td>'+data["orderListData"][i]["TotalAmount"]+'</td>';
			htmlStr += '<td>'+data["orderListData"][i]["Nums"]+'</td>';
			htmlStr += '<td>'+data["orderListData"][i]["Point"]+'</td>';
			htmlStr += '<td>'+data["orderListData"][i]["UserName"]+'</td>';
			htmlStr += '<td><a href=javascript:$ddf_order.loadOrderDetail("'+data["orderListData"][i]["OrderId"]+'")>详情</a></td>';
			htmlStr += '</tr>';
		}

		$("#orderList").html(htmlStr);

//		setPage(0,data["pageNumber"],data["totalCount"],data["totalPage"],"$ddf_order");
		$('#footPageDivOrderList').ddf_pagination(data["pageSize"],data["pageNumber"],data["totalCount"],data["totalPage"],{  
			 
			 changePageCallback:function(pageSize,page){  
				 getMyOrders(page,pageSize,beginDate,endDate,beginAmt,endAmt,paymentId,erpOrderType,beginnums,endnums,orderstatusId,orderId,payStatus,userId,searchUserName);
				 _page=page;
			 },
			 changePageSizeCallBack:function(pageSize){
				 getMyOrders(1,pageSize,beginDate,endDate,beginAmt,endAmt,paymentId,erpOrderType,beginnums,endnums,orderstatusId,orderId,payStatus,userId,searchUserName);
				 _pageSize=pageSize;
			 } 
	     }); 
		_totalCount=data["totalCount"];
	}else{
		$("#orderList").html("");
		$("#footPageDivOrderList").html("");
		base.tips_error(data["message"]);
	}

//	pageSize=10;
	base.cancelLoading();
	
}

/**
 * 重置参数
 */
function resetSearchParams(){
	
	beginDate="";
	endDate="";
	beginAmt="";
	endAmt="";
	paymentId="";
	erpOrderType="";
	beginnums="";
	endnums="";
	orderstatusId="";
	orderId="";
	payStatus="";
	searchUserName="";
//	userId="";
	$("#obeginDate").val("");
	
	$("#oendDate").val("");
	
	$("#beginAmt").val("");
	
	$("#endAmt").val("");
	
	$("#beginnums").val("");
	
	$("#endnums").val("");
	
	$("#orderId").val("");
	
	$("#searchUserName").val("");
	
	
	setOrderTypeId("","请选择");
	
	setOrderStatusId("","请选择");

	setPaymentId("","请选择");
		
	setPayStatus(0,"全部");
	
	$("#payStatusDiv").css("display","none");
//	showDiv("payStatusDiv");
	
	

	
}


/**
 * 设置支付方式
 * @param _paymentId
 */
function setPaymentId(_paymentId,paymentName){
	
	paymentId=_paymentId;
	
	if(paymentId=="2"){
		
		$("#payStatusDiv").css("display","inline");
		
		
		
	}else{
		
		$("#payStatusDiv").css("display","none");
		
	}
		
	
	$("#paymentName").html(paymentName);
	
}

/**
 * 设置在线支付-支付状态
 * @param _payStatus
 */
function setPayStatus(_payStatus,payStatusName){
	
	
	payStatus=_payStatus;
	
	$("#payStatusName").html(payStatusName);
}

/**
 * 设置订单类型
 * @param _erpOrderType
 */
function setOrderTypeId(_erpOrderType,orderTypeName){
	
	erpOrderType=_erpOrderType;
	
	$("#orderTypeName").html(orderTypeName);
}

/**
 * 设置订单状态
 * @param _orderstatusId
 */
function setOrderStatusId(_orderstatusId,orderStatusName){
	
	orderstatusId=_orderstatusId;
	
	$("#orderStatusName").html(orderStatusName);
	
}


/**
 * 设置业务类型
 * @param _businessTypeId
 */
function setBusinessTypeId(_businessTypeId,businessTypeName){
	
	businessTypeId=_businessTypeId;
	
	$("#businessTypeName").html(businessTypeName);
	
}




/**
 * 搜索订单
 */
function searchOrder(){
	
	
	orderId=$("#orderId").val();
	
	beginDate=$("#obeginDate").val();
	
	endDate=$("#oendDate").val();
	
	beginAmt=$("#beginAmt").val();
	
	endAmt=$("#endAmt").val();
	
	beginnums=$("#beginnums").val();
	
	endnums=$("#endnums").val();
	
	searchUserName=$("#searchUserName").val();
	
	if(!isNull(beginAmt) && !isNumber(beginAmt)){
		
		base.tips_error("开始金额非法");
   	 
   	 	return;
		
	}
	
	if(!isNull(endAmt) && !isNumber(endAmt)){
		base.tips_error("结束金额非法");
   	 	return;
		
	}
    	
	if( parseFloat(beginAmt) > parseFloat(endAmt)){
		base.tips_error("查询条件的起始金额不能大于结束金额");
   	 	return;
	}
	
	
	if(!isNull(beginnums) &&  !isInteger(beginnums)){
		
		base.tips_error("商品数量非法");
		
		return;
	}
	
	if(!isNull(endnums) &&  !isInteger(endnums)){
		
		base.tips_error("商品数量非法");
		
		return;
	}
	
	if(!base.checkDate(beginDate,endDate))
		return;
    
    if(parseInt(beginnums)>parseInt(endnums)){
    	
    	base.tips_error("查询条件的开始数量不能大于结束数量");
    	 
    	return;
    }
	getMyOrders(1, pageSize,beginDate,endDate,beginAmt,endAmt,paymentId,erpOrderType,beginnums,endnums,orderstatusId,orderId,payStatus,userId,searchUserName);
	
}

/**
 * 支付方式列表
 */
function getPaymentsList(){
//	DDF_AsyncRequest("POST",ddf.order.getPaymentsList,"",'$ddf_order.getPaymentsListCallBack(data)');
eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.order.getPaymentsList,""));
		
		getPaymentsListCallBack(data);
		
	}))().start();
	
}

/**
 * 支付方式列表_回调函数
 */
function getPaymentsListCallBack(data){
	
	
	var htmlStr="";
	
	for(var i=0;i<data["paymentsListData"].length;i++){
		
		htmlStr+='<li><a href=javascript:$ddf_order.setPaymentId("'+data["paymentsListData"][i]["PAYMENT_ID"]+'","'+data["paymentsListData"][i]["PAYMENT_NAME"]+'")>'+data["paymentsListData"][i]["PAYMENT_NAME"]+'</a></li>';
		
	}
	
	$("#paymentList").html('<li><a href=javascript:$ddf_order.setPaymentId("","请选择")>请选择</a></li>'+htmlStr);
	
}



/**
 * 订单类型列表
 */
function getErpOrderTypesList(){
		
//	DDF_AsyncRequest("POST",ddf.order.getErpOrderTypesList,"",'$ddf_order.getErpOrderTypesListCallBack(data)');
      eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.order.getErpOrderTypesList,""));
		
		getErpOrderTypesListCallBack(data);
		
	}))().start();
}

/**
 * 订单类型列表_回调函数
 */
function getErpOrderTypesListCallBack(data){
	
	
	var htmlStr="";
	
	for(var i=0;i<data["orderTypesListData"].length;i++){
		
		htmlStr+='<li><a href=javascript:$ddf_order.setOrderTypeId("'+data["orderTypesListData"][i]["ORDER_TYPE_ID"]+'","'+data["orderTypesListData"][i]["ORDER_TYPE_NAME"]+'")>'+data["orderTypesListData"][i]["ORDER_TYPE_NAME"]+'</a></li>';
		
	}
	
	$("#orderTypeList").html('<li><a href=javascript:$ddf_order.setOrderTypeId("","请选择")>请选择</a></li>'+htmlStr);
	
}


/**
 * 订单状态列表
 */
function getOrderstatusList(){
	
//	DDF_AsyncRequest("POST",ddf.order.getOrderstatusList,"",'$ddf_order.getOrderstatusListCallBack(data)');
   eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.order.getOrderstatusList,""));
		
		getOrderstatusListCallBack(data);
		
	}))().start();
}

/**
 * 订单状态列表_回调函数
 */
function getOrderstatusListCallBack(data){
	
	
	var htmlStr="";
	
	for(var i=0;i<data["orderStatusListData"].length;i++){
		
		htmlStr+='<li><a href=javascript:$ddf_order.setOrderStatusId("'+data["orderStatusListData"][i]["ORDER_STATUS_ID"]+'","'+data["orderStatusListData"][i]["ORDER_STATUS_NAME"]+'")>'+data["orderStatusListData"][i]["ORDER_STATUS_NAME"]+'</a></li>';
		
	}
	
	$("#orderStatusList").html('<li><a href=javascript:$ddf_order.setOrderStatusId("","请选择")>请选择</a></li>'+htmlStr);
	
}



/**
 * 查询订单详情
 */

function loadOrderDetail(_orderId){
	history.addHis(this,arguments);//增加历史
	orderId=_orderId;
//	formIndex=parseInt(formIndex)+1;
	
	var params={
			
			"orderId":orderId
			
	        };
	
	
	base.showLoading();

//	DDF_AsyncRequest("POST",ddf.order.getOrderDetails,params,'$ddf_order.loadOrderDetailCallBack(data)');
	 eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.order.getOrderDetails,params));
			
			loadOrderDetailCallBack(data);
			
		}))().start();

	
	
}

/**
 * 查询订单详情回调函数
 */
function loadOrderDetailCallBack(data){
	
var htmlStr="";
	
	htmlStr += '<div id="content-header">';
	htmlStr += '<div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:$ddf_order.showDiv("content'+parseInt(formIndex)+'")>订单管理</a><a href="javascript:void(0)" class="current">订单详情</a></div>';
	htmlStr += '</div>    ';

	htmlStr += '<div class="container-fluid">';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">';
	htmlStr += '<div id="alert-tips2" ></div>';
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title">';
	htmlStr += '<span class="icon"><i class="icon-reorder"></i></span>';
	htmlStr += '<h5>操作</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content">';
	//htmlStr += '<button type="button" class="btn btn-success" onClick=$ddf_order.toPrintOrderDetail('+data["orderId"]+')>打印订单</button>';
	if(isInstalledLodop()){
		htmlStr += ' <button type="button" class="btn btn-danger" onClick=$ddf_order.loadPrintOrder("'+data["orderId"]+'")>打印</button>';
	}
	htmlStr += ' <button type="button" class="btn btn-info" onClick=$ddf_order.showDiv("content'+parseInt(formIndex)+'")>返回</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
	
	//<%--交易关闭(取消)--%>
//	if(
//		//<%-- 在线付款 普通商品  待付款5,待发货1,拒绝收货6,客服调解7 --%>
//		( data.paymentId==2 && data.businessId=='00' && (data["statusId"]==5 || data["statusId"]==1 || data["statusId"]==6 || data["statusId"]==7) )
//		||
//		//<%-- 货到付款 普通商品 待发货1 --%>
//		( data.paymentId==1 && data.businessId=='00' && data["statusId"]==1 )
//		||
//		//<%-- app/web 增值业务  待付款5,待发货1,待收货2 --%>
//		( (data.orderTypeId==1 || data.orderTypeId==2) && data.businessId != '00' && (data["statusId"]==5 || data["statusId"]==1 || data["statusId"]==2) )
//		||
//		//<%-- pos 增值业务  待付款5) --%>
//		( data.orderTypeId==3 && data.businessId != '00' && data["statusId"]==5 )
//	  ){
//		
//
//		htmlStr += '<button type="button" class="btn btn-warn" onclick=$ddf_order.processOrder(4,"'+data["orderId"]+'","确定取消该订单吗?")>取消</button>&nbsp;&nbsp;';
//	
//	}
	//<%--交易关闭(取消)--%>
	if(data["allowCancelOrder"]=="1"){
		htmlStr += '<button type="button" class="btn btn-warn" onclick=$ddf_order.openCancelOrderReason("取消订单",4,"'+data["orderId"]+'","'+data["statusId"]+'","确定取消该订单吗?","取消")>取消订单</button>&nbsp;&nbsp;';
	}
	
	//<%-- 发货 --%>
//	if(
//		//<%-- 在线付款 普通商品  待发货1 --%>
//		( data.paymentId==2 && data.businessId=='00' && data["statusId"]==1 )
//		||
//		//<%-- 货到付款 普通商品 待发货1 --%>
//		( data.paymentId==1 && data.businessId=='00' && data["statusId"]==1 )
//		||
//		//<%-- app/web 增值业务  待发货1 --%>
//		( (data.orderTypeId==1 || data.orderTypeId==2) && data.businessId != '00' && data["statusId"]==1)
//			
//	){
//		
//		htmlStr += '&nbsp;&nbsp;<button type="button" class="btn btn-warn" onclick=$ddf_order.processOrder(2,"'+data["orderId"]+'","确定发货吗?")>发货</button>&nbsp;&nbsp;';
//		
//	}
	//<%-- 发货 --%>
	if(data["allowShippingOrder"]=="1"){
		htmlStr += '&nbsp;&nbsp;<button type="button" class="btn btn-warn" onclick=$ddf_order.processOrder(2,"'+data["orderId"]+'","确定发货吗?")>发货</button>&nbsp;&nbsp;';
	}
	
	//<%-- 提醒用户收货 --%>
//	if(
//		//<%-- 在线付款 普通商品  待收货2 --%>
//		( data.paymentId==2 && data.businessId=='00' && data["statusId"]==2 )
//		||
//		//<%-- 货到付款 普通商品  待收货2 --%>
//		( data.paymentId==1 && data.businessId=='00' && data["statusId"]==2 )
//	){
//		
//		htmlStr += '&nbsp;&nbsp;<button type="button" class="btn btn-warn" onclick=alert("确定提醒用户收货吗?")>提醒用户收货</button>&nbsp;&nbsp;';
//		
//	}
	//是否允许提醒按钮出现
	if(data["allowRemindToUser"]=="1"){
		htmlStr += '&nbsp;&nbsp;<button type="button" class="btn btn-warn" onclick=$ddf_order.remindToUser("'+data["orderId"]+'","确定提醒用户收货吗?")>提醒用户收货</button>&nbsp;&nbsp;';
	}
	
	//<%-- 申请客服介入 --%>
//	if(
//		//<%-- 在线付款 普通商品  拒绝收货6 --%>
//		( data.paymentId==2 && data.businessId=='00' && data["statusId"]==6 )
//			
//	){
//		htmlStr += '&nbsp;&nbsp;<button type="button" class="btn btn-warn" onclick=alert("确定申请客服介入吗?")>申请客服介入</button>&nbsp;&nbsp;';
//	}
	//<%-- 申请客服介入 --%>
	if(data["allowApply"]=="1"){
		htmlStr += '&nbsp;&nbsp;<button type="button" class="btn btn-warn" onclick=$ddf_order.openCancelOrderReason("申请客服介入",6,"'+data["orderId"]+'","'+data["statusId"]+'","确定申请客服介入吗?","申请客服介入")>申请客服介入</button>&nbsp;&nbsp;';
	}
	//<%-- 交易成功(完成) --%>
//	if(
//		//<%-- app/web 增值业务  待收货2 --%>
//		( (data.orderTypeId==1 || data.orderTypeId==2) && data.businessId != '00' && data["statusId"]==2 )
//	){
//		
//		htmlStr += '&nbsp;&nbsp;<button type="button" class="btn btn-warn" onclick=$ddf_order.processOrder(3,"'+data["orderId"]+'","确定完成该订单吗?")>完成</button>&nbsp;&nbsp;';
//		
//	}
	//<%-- 交易成功(完成) --%>
	if(data["allowFinish"]=="1"){
		htmlStr += '&nbsp;&nbsp;<button type="button" class="btn btn-warn" onclick=$ddf_order.processOrder(3,"'+data["orderId"]+'","确定完成该订单吗?")>完成</button>&nbsp;&nbsp;';

	}
	//提示消息
	htmlStr += "<span style='color:red;'>"+data.timeoutMessage+"</span>";
	
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title">';
	htmlStr += '<span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>订单信息</h5>';
	htmlStr += '</div>        ';
	htmlStr += '<div class="widget-content nopadding dataTables_wrapper">';
	htmlStr += '<table class="table table-bordered data-table">';
	htmlStr += '<tbody>';
	htmlStr += '<tr><td><span>订单状态：</span><span style="color:red;font-weight:blod;">'+data["statusName"]+'</span></td><td>订单金额：</span><span>'+data["totalAmount"]+'</span></td><td>积分：</span><span>'+data["point"]+'</span></td></tr>';
	htmlStr += '<tr><td><span>商家：</span><span>'+data["shopName"]+'</span></td><td>所属业务：</span><span>'+data["businessName"]+'</span></td><td><span>配送方式：</span><span>'+data["deliveryName"]+'</span></td></tr>';
	htmlStr += '<tr><td><span>订单号：</span><span>'+data["orderId"]+'</span></td><td>订单来源：</span><span>'+data["orderTypeName"]+'</span></td><td><span>创建时间：</span><span>'+data["orderDate"]+'</span></td></tr>';
	htmlStr += '<tr><td><span>付款时间：'+data["payTime"]+'</span></td><td><span>确认时间：'+data["finishTime"]+'</span></td><td><span>支付方式：</span>'+data["payMentName"]+'</td></tr>';
	htmlStr += '<tr><td><span>刷卡批次号：'+data["batchNo"]+'</span></td><td><span>刷卡凭证号：'+data["vouchNo"]+'</span></td>';
	
	if(data["deliveryId"]=="2"){
		htmlStr += '<td><span>自提时间：</span><span>'+data["shipTime"]+'</span></td>';
	}else{
		htmlStr += '<td><span>送货时间：</span><span>'+data["shipTime"]+'</span></td>';
	}
	
	htmlStr += '</tr>';
	//if(data["statusId"]==4){
		
		htmlStr += '<tr><td colspan="3"><span>关闭原因：'+getReason(data["closeReason"])+'</span></td></tr>';
//	}
	//if(data["statusId"]==6){
		htmlStr += '<tr><td><span>拒绝收货时间：'+data["rejectReceiptTime"]+'</span></td><td><span>拒绝收货原因：'+getReason(data["rejectReceiptReason"])+'</span></td><td></td></tr>';
	//}
	//if(data["statusId"]==7){
		htmlStr += '<tr><td><span>用户申请客服介入时间：'+data["userMediateTime"]+'</span></td><td><span>用户申请客服介入原因：'+getReason(data["userMediateReason"])+'</span></td><td></td></tr>';
		htmlStr += '<tr><td><span>商家申请客服介入时间：'+data["shopMediateTime"]+'</span></td><td><span>商家申请客服介入原因：'+getReason(data["shopMediateReason"])+'</span></td><td></td></tr>';
	//}
	
	htmlStr += '<tr><td><span>收货人姓名：</span><span>'+data["shipName"]+'</span></td><td><span>收货人电话：</span><span>'+data["shipMobile"]+'</span></td><td><span>SN码：</span>'+data["sn"]+'</td></tr>';
	htmlStr += '<tr><td colspan="3"><span>收货地址：</span><span>'+data["shipAddress"]+'</span></td></tr>';
	htmlStr += '<tr><td colspan="3"><span>详情：</span><span>'+data["memo"]+'</span></td></tr>';
	htmlStr += '</tbody>';
	htmlStr += '</table>  	';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title">';
	htmlStr += '<span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>订单追踪</h5>';
	htmlStr += '</div>        ';
	htmlStr += '<div class="widget-content nopadding dataTables_wrapper">';
	htmlStr += '<table class="table table-bordered data-table">';
	htmlStr += '<thead>';
	htmlStr += '<tr><th>处理时间</th><th>处理信息</th><th>操作人</th></tr>';
	htmlStr += '</thead>';
	htmlStr += '<tbody>';
	for(var i=0;i<data["orderlogs"].length;i++){

		htmlStr += '<tr><td>'+data["orderlogs"][i]["createTime"]+'</td><td>'+data["orderlogs"][i]["memo"]+'</td><td>'+data["orderlogs"][i]["operator"]+'</td></tr>  ';
	}
	htmlStr += '</tbody>';
	htmlStr += '</table>  	';
	htmlStr += '</div>';
	htmlStr += '</div>  ';
	
	/*
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title">';
	htmlStr += '<span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>订单留言</h5>';
	htmlStr += '</div>        ';
	htmlStr += '<div class="widget-content nopadding dataTables_wrapper">';
	htmlStr += '<table class="table table-bordered data-table">';
	htmlStr += '<thead>';
	htmlStr += '<tr><th>留言时间</th><th>留言内容</th><th>附件</th></tr>';
	htmlStr += '</thead>';
	htmlStr += '<tbody>';
	
	for(var i=0;i<data["orderMessage"].length;i++){

		htmlStr += '<tr><td>'+data["orderMessage"][i]["createTime"]+'</td><td>'+data["orderMessage"][i]["content"]+'</td><td>'+data["orderMessage"][i]["attach"]+'</td></tr>  ';
	}
	htmlStr += '</tbody>';
	htmlStr += '</table>  	';
	htmlStr += '</div>';
	htmlStr += '</div>  ';
	*/
	
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title">';
	htmlStr += '<span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>商品信息</h5>';
	htmlStr += '</div>        ';
	htmlStr += '<div class="widget-content nopadding dataTables_wrapper">';
	htmlStr += '<table class="table table-bordered data-table">';
	htmlStr += '<thead>';
	htmlStr += '<tr><th>商品条形码</th><th>商品名称</th><th>商品价格</th><th>商品数量</th><th>小计</th></tr>';
	htmlStr += '</thead>';
	htmlStr += '<tbody>';
	for(var i=0;i<data["ordergoods"].length;i++){
		htmlStr += '<tr>';
		htmlStr += '<td>'+data["ordergoods"][i]["barcode"]+'</td>';
		htmlStr += '<td>';
		htmlStr += '<table>';
		htmlStr += '<tr><td><span class="table-imgspan"><img src="'+fileOpenUrl+data["ordergoods"][i]["picDefault"]+'"/></span></td><td>'+data["ordergoods"][i]["merchandiseName"]+'</td></tr>';
		htmlStr += '</table> ';
		htmlStr += '</td>    ';
		htmlStr += '</td>';
		htmlStr += '<td>'+data["ordergoods"][i]["price"]+'</td>';
		htmlStr += '<td>'+data["ordergoods"][i]["nums"]+'</td>';
		htmlStr += '<td>'+data["ordergoods"][i]["amount"]+'</td>';
		htmlStr += '</tr> ';
		
	}
	
	
	htmlStr += '<tr>';
	htmlStr += '<td colspan="5"> ';
	htmlStr += '<div class="pull-right">';
	htmlStr += '<h5><span>商品价格总计：</span>'+Number(data["merchandiseAmountMoney"]).toFixed(2)+'元</h5>';
	htmlStr += '<h5 class="pull-right"><span>配送费：</span>'+Number(data["deliveryAmount"]).toFixed(2)+'元</h5>';
	htmlStr += ' </div>';
	htmlStr += '</td>';
	htmlStr += '</tr> ';
	
	htmlStr += '</tbody>';
	htmlStr += '</table>  ';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"><span class="icon"><i class="icon-comments"></i></span>';
	htmlStr += '<h5>留言情况</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content nopadding collapse in" id="collapseG2">';
	htmlStr += '<ul class="recent-posts">';
	
	for (var i = 0; i < data["orderMessage"].length; i++) {
		htmlStr += '<li>';
		htmlStr += '<div class="user-thumb"> <img alt="User" src="img/demo/av1.jpg"> </div>';
		htmlStr += '<div class="article-post"> <span class="user-info"> '+data["orderMessage"][i]["createName"]+'&nbsp;&nbsp;留言&nbsp;&nbsp;/&nbsp;&nbsp;时间：'+data["orderMessage"][i]["createTime"]+' </span>';
		htmlStr += '<pre>'+data["orderMessage"][i]["content"]+'</pre>';
		htmlStr += '<div class="user_thumb_pic">';
		if(data["orderMessage"][i]["attach"]!=""){
			var allUrl=data["orderMessage"][i]["attach"].split(",");
			for (var j = 0; j < allUrl.length; j++) {
				if(allUrl[j]!=""){
					htmlStr += '<a class="lightbox_trigger" href="'+fileOpenUrl+allUrl[j]+'"><img alt="User" src="'+fileOpenUrl+allUrl[j]+'"></a>';
				}
			}
		}
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '</li>';
	}
	
	htmlStr += '</ul>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div>'; 

	
//	$("#content0").css("display","none");
	
//	$("#content2").css("display","block");
	showDiv("content"+(parseInt(formIndex)+1));
	
	$("#content"+(parseInt(formIndex)+1)).html(htmlStr);
	
	base.cancelLoading();
	
	
	$('.lightbox_trigger').click(function(e) {
		
		e.preventDefault();
		
		var image_href = $(this).attr("href");
		
		if ($('#lightbox').length > 0) {
			
			$('#imgbox').html('<img src="' + image_href + '" /><p><i class="icon-remove icon-white"></i></p>');
		   	
			$('#lightbox').slideDown(500);
		}
		
		else { 
			var lightbox = 
			'<div id="lightbox" style="display:none;">' +
				'<div id="imgbox"><img src="' + image_href +'" />' + 
					'<p><i class="icon-remove icon-white"></i></p>' +
				'</div>' +	
			'</div>';
				
			$('body').append(lightbox);
			$('#lightbox').slideDown(500);
		}
		
	});
	
	$('#lightbox').live('click', function() { 
		$('#lightbox').hide(200);
	});
}

/**
 * 打印订单
 */
exports.loadPrintOrder = function(_orderId){
	if(document.getElementById("_upload_frame_autoprint")==null){
		$(document.body).append('<iframe class="opacitystyle" id="_upload_frame_autoprint" name="_upload_frame_autoprint"></iframe>');
	}
	get2post(CTX+"/admin/printOrder.jsp?orderId="+_orderId,"_upload_frame_autoprint");
	
}


/**
 * 打开取消订单原因页面
 */
exports.openCancelOrderReason=function(_title,_type,_orderId,_orderStatus,_tip,_processCode){
	
//	var gnl=confirm(_tip);
//	
//	if(gnl!=true){
//		return;
//	}
	
	
	var htmlStr="";
	htmlStr += '<div id="content-header">';
	htmlStr += '<div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:$ddf_order.showDiv("content'+parseInt(formIndex)+'")>订单管理</a><a href=javascript:$ddf_order.showDiv("content'+parseInt((formIndex)+1)+'")>订单详情</a><a href="javascript:void(0)" class="current">'+_title+'</a></div>';
	htmlStr += '</div>    ';

	htmlStr += '<div class="container-fluid">';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">';
	htmlStr += '<div id="alert-tips2" ></div>';
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title">';
	htmlStr += '<span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>'+_title+'原因</h5>';
	htmlStr += '</div>';
	
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<div class="form-horizontal">';
	htmlStr += '<div class="control-group" id="radioReasonDiv">';
	htmlStr += '<label class="control-label">'+_title+'原因：</label>';
	htmlStr += '<div class="controls" id="reasonListDiv" >';
	
	htmlStr += '</div>';
	
//	htmlStr += '<div class="controls" >';
//	
//	if(_statusId=="5"||_statusId=="1"||_statusId=="2"){
//		htmlStr += '<label><input type="radio" name="reasons" value="6" />送货范围以外 </label>';
//		htmlStr += '<label><input type="radio" name="reasons" value="7" />未到起送金额 </label>';
//		htmlStr += '<label><input type="radio" name="reasons" value="8" />库存不足 </label>';
//		htmlStr += '<label><input type="radio" name="reasons" value="10"/>其他</label>';
//	}else if(_statusId=="6"||_statusId=="7"){
//		htmlStr += '<label><input type="radio" name="reasons" value="3" />货不对板 </label>';
//		htmlStr += '<label><input type="radio" name="reasons" value="4" />发错货 </label>';
//		htmlStr += '<label><input type="radio" name="reasons" value="5" />质量问题 </label>';
//		htmlStr += '<label><input type="radio" name="reasons" value="9" />用户不想要了 </label>';
//		htmlStr += '<label><input type="radio" name="reasons" value="10"/>其他</label>';
//	}
//	
//	htmlStr += '</div>';
	htmlStr += '</div> ';
	
	htmlStr += '<div class="control-group" id="otherReasonDiv" style="display:none">';
	htmlStr += '<label class="control-label">具体原因：</label>';
	htmlStr += '<div class="controls"><textarea class="span9" id="reasonMemo"> </textarea></div>';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group" id="reasonImage" style="display:none">';
	htmlStr += '<label class="control-label">上传图片：</label>';
	htmlStr += ' <div class="controls noheight">';
	htmlStr += '<button id="uploadBtn" class="btn btn-primary" type="button" onclick="$ddf_order.uploadReasonImg()" >上传照片</button> <div class="help-inline">最多可上传5张图片</div><br/><br/>';
	htmlStr += '<div id="reasonLinkDiv" style="display:none"></div>';
//	htmlStr += '<input type="file" multiple="multiple" />&nbsp;&nbsp;&nbsp;&nbsp;<div class="help-inline">最多可上传5张图片</div>';
	htmlStr += '<ul class="thumbnails">';
	
	for(var i=0;i<maxImgCount;i++){
		htmlStr += '<li class="span2 shopsPhotos"> <a id="aLink'+i+'" class="lightbox_trigger" href="'+defalueImgPath+'"><img id="imgLink'+i+'" src="'+defalueImgPath+'" alt="" > </a>';
		htmlStr += '<div class="actions"> ';
		htmlStr += '<a id="d'+i+'" title="" class="delete_this" href="#"><i class="icon-trash"></i></a> &nbsp;';
		htmlStr += '</div>';
		htmlStr += '</li>';
	}
	
	
	htmlStr += '</ul>';
	htmlStr += '</div></div>';
	
	htmlStr += '<div class="form-actions">';
	htmlStr += '  <button class="btn btn-primary" type="button" onClick=$ddf_order.processOrder("'+_type+'","'+_orderId+'","'+_tip+'")>保存</button>';
	htmlStr += '  <button class="btn btn-info" type="button" onClick=$ddf_order.showDiv("content'+(parseInt(formIndex)+1)+'")>返回</button>';
	htmlStr += '</div>        ';
	htmlStr += '</div>';
	
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	
	showDiv("content"+(parseInt(formIndex)+2));
	
	$("#content"+(parseInt(formIndex)+2)).html(htmlStr);
	
	
	base.cancelLoading();
	
	
	$('#radioReasonDiv').click(function(e) {
		var reasonId=$('input[name="reasons"]:checked').val();
		if(reasonId=="10"){
			$("#otherReasonDiv").css("display","block");
			if(_type=="6"){
				$("#reasonImage").css("display","block");
			}
		}else{
			$("#otherReasonDiv").css("display","none");
			if(_type=="6"){
				$("#reasonImage").css("display","none");
			}
		}
		
	});
	
	$(".delete_this").on("click",function(){
		//$(this).parents(".shopsPhotos").find("input").click();	
		var sort = $(this).attr("id");
		var index=sort.substring(1);
		//判断点击删除按钮的位置是否已经上传图片
		if($("#imgLink"+index).attr("src")==defalueImgPath){
			base.tips_error("此位置没有照片，无法删除！");
			return;
		}
		deleteReasonImg(index);
		
	});

	$('.lightbox_trigger').click(function(e) {
		
		e.preventDefault();
		
		var image_href = $(this).attr("href");
		
		if ($('#lightbox').length > 0) {
			
			$('#imgbox').html('<img src="' + image_href + '" /><p><i class="icon-remove icon-white"></i></p>');
		   	
			$('#lightbox').slideDown(500);
		}
		
		else { 
			var lightbox = 
			'<div id="lightbox" style="display:none;">' +
				'<div id="imgbox"><img src="' + image_href +'" />' + 
					'<p><i class="icon-remove icon-white"></i></p>' +
				'</div>' +	
			'</div>';
				
			$('body').append(lightbox);
			$('#lightbox').slideDown(500);
		}
		
	});
	
	$('#lightbox').live('click', function() { 
		$('#lightbox').hide(200);
	});
	
	getReasonList(_orderId,_processCode);//获得原因列表
};


/*
 * 加载原因列表
 */
function getReasonList(_orderId,_processCode){
	
	var params={
			"processCode":_processCode,
			"orderId":_orderId
	};
	
	base.showLoading();

	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.order.loadReasonList,params));
		
		loadReasonListCallBack(data);
		
	}))().start();
	
	
}

function loadReasonListCallBack(data){
	
	if(data["code"]==1){
		var htmlStr="";
		for (var i = 0; i < data["reasonList"].length; i++) {
			htmlStr += '<label><input type="radio" name="reasons" value="'+data["reasonList"][i]["reasonCode"]+'" />'+data["reasonList"][i]["reasonName"]+'</label>';
		}
		$("#reasonListDiv").html(htmlStr);
		
		//当列表只有一个选项，则自动选中
		if(data["reasonList"].length==1){
			$("input[type='radio']").eq(0).attr("checked",true);
			$('#radioReasonDiv').click();
		}
	}
	
	
	base.cancelLoading();
	
}

var allowNum=0;
exports.uploadReasonImg=function(){
	//计算可允许用户上传图片的数目 
	allowNum=maxImgCount-currentMaxImgIndex-1;
	//开始上传照片
	upload.ddf_upload_reasonPhots("reasonLinkDiv","/order/orderID/reasonPhotos","$ddf_order.uploadReasonPhotosCallBack",allowNum);

};

function deleteReasonImg(clickId){
	//删除一张图片后，把后边的照片往前移
	for(var i=0;i<(parseInt(currentMaxImgIndex)-parseInt(clickId));i++){
		$("#aLink"+(parseInt(clickId)+i)).attr("href",$("#aLink"+(parseInt(clickId)+i+1)).attr("href"));
		$("#imgLink"+(parseInt(clickId)+i)).attr("src",$("#imgLink"+(parseInt(clickId)+i+1)).attr("src"));
	}
	$("#aLink"+(parseInt(currentMaxImgIndex))).attr("href",defalueImgPath);
	$("#imgLink"+(parseInt(currentMaxImgIndex))).attr("src",defalueImgPath);
	currentMaxImgIndex--;//可允许上传数-1
	if(currentMaxImgIndex<0){
		currentMaxImgIndex=-1;//当相片下标小于第一张下标，则固定在第一张下标
	}else if(currentMaxImgIndex>4){
		currentMaxImgIndex=4;//当相片下标小于第一张下标，则固定在第一张下标
	}
	$("#uploadBtn").attr("disabled",false);//设置上传按钮可点
}


exports.uploadReasonPhotosCallBack=function(dataObj){
	var dataPath = "";
	if(dataObj.code == "1"){
		
		
		for(var i=0;i<dataObj.files.length;i++){
			if(dataObj.files[i].repCode=="1"){
				dataPath = dataObj.files[i].path;
				
				//上传成功后，自动从图片不为空的位置加载
				for(var j=0;j<maxImgCount;j++){
					if($("#imgLink"+j).attr("src")==defalueImgPath){
						$("#imgLink"+j).attr("src",fileOpenUrl+dataPath);
						$("#aLink"+j).attr("href",fileOpenUrl+dataPath);
						currentMaxImgIndex=j;
						break;
					}
				}
				//当最后一张照片路径加载图片后，上传按钮不可点
				if($("#imgLink"+(parseInt(maxImgCount)-1)).attr("src")!=defalueImgPath){
					$("#uploadBtn").attr("disabled","true");
				}
			}else{
				base.tips_error("上传失败!");
			}
		}
	}
	base.cancelLoading();
};



/**
 * 取消订单
 */
function processOrder(type,orderId,tip){
	
		var gnl=confirm(tip);
	

		if (gnl == true) {

			var params = {};
			
			if(type=="4"){//当操作类型是“取消”时，获取取消原因
				var reason=$('input[name="reasons"]:checked').val();
				params["reason"]=reason;
				if(reason=="10"){//当选择“其他”原因时，获取具体原因
					var memo = $("#reasonMemo").val();
					params["memo"]=memo;
				}
			}else if(type=="6"){//客服介入
				var reason=$('input[name="reasons"]:checked').val();
				params["reason"]=reason;
				if(reason=="10"){//当选择“其他”原因时，获取具体原因
					var memo = $("#reasonMemo").val();
					params["memo"]=memo;
				}
				if($("#reasonImage").css("display")=="block"){
					var fileUrl="";//附件路径
					for (var i = 0; i <= currentMaxImgIndex; i++) {
						beginIndex=fileOpenUrl.length;
						
						path=$("#imgLink"+i).attr("src").substring(beginIndex);
						fileUrl+=path+",";
					}
					params["fileUrl"]=fileUrl;
				}
			}
			
			params["type"]=type;
			params["orderId"]=orderId;
	
			base.showLoading();
//	
//			DDF_AsyncRequest("POST", ddf.order.processOrder, params,
//					'$ddf_order.processOrderCallBack(data)');
			eval(Wind.compile("async",function(){
				
				var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.order.processOrder,params));
				
				processOrderCallBack(data);
				
			}))().start();
		}
}

/**
 * 取消订单_回调函数
 */
function processOrderCallBack(data){
	if(data["code"]==1){
		
		loadOrderDetail(orderId);
		
	}else{
		
		 base.tips_error(data["message"]);
	}

	base.cancelLoading();
	
}

/**
 * 提醒用户收货
 */
exports.remindToUser=function(_orderId,tip){
	var gnl=confirm(tip);

	if (gnl == true) {

		var params = {
			"orderId" : _orderId

		};
		
		base.showLoading();
		
		eval(Wind.compile("async",function(){

			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.order.remindToUser,params));

			remindToUserCallBack(data);

		}))().start();
	}
	
};

/**
 * 取消订单_回调函数
 */
function remindToUserCallBack(data){
	
	if(data["code"]==1){
		base.tips("提醒用户收货成功");
	}else{
		base.tips_error(data["message"]);
	}
	base.cancelLoading();
};

/**
 * 打印订单
 */
function toPrintOrderDetail(_orderId){

	var params = {
			"orderId" : orderId

		};
	
	base.showLoading();

//	DDF_AsyncRequest("POST", ddf.order.printOrderDetail, params,'$ddf_order.toPrintOrderDetailCallBack(data)');
	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.order.printOrderDetail,params));
		
		toPrintOrderDetailCallBack(data);
		
	}))().start();
	
}

function toPrintOrderDetailCallBack(data){
	if(data["code"]==1){
		base.tips("订单打印成功");
	}else{
		base.tips_error(data["message"]);
	}
	base.cancelLoading();
}






/**
 * 获取理由信息
 */
var reasonArray=new Array("","不想要了","重复下单了","货不对板","发错货","质量问题","超出配送范围","未到起送金额","库存不足","用户不想要了","其他");
function getReason(index){
	
	if(index=="" || typeof index=="undefined"){
		
		return "";

	}
	return reasonArray[parseInt(index)];
}





/**
 * 区域显示
 */
function showDiv(block){
	
	$("#content > div").hide();
	
	if($("#"+block).length<=0){
		
		$("#content").append('<div id="'+block+'"></div>'); 
		
	}else{
		
		$("#"+block).show();
	}
	
	if(block==("content"+formIndex)){
		orderId="";
		if(firstLoadFlag){
			firstLoadFlag=false;
		}else{
			getMyOrders(_page,_pageSize,beginDate,endDate,beginAmt,endAmt,paymentId,erpOrderType,beginnums,endnums,orderstatusId,orderId,payStatus,userId,searchUserName);
		}

	}
	
}


//暴露方法
//exports={};
//exports.loadOrderList=loadOrderList;
exports.getMyOrders=getMyOrders;
exports.getMyOrdersCallBack=getMyOrdersCallBack;
exports.resetSearchParams=resetSearchParams;
exports.setPaymentId=setPaymentId;
exports.setPayStatus=setPayStatus;
exports.setOrderTypeId=setOrderTypeId;
exports.setOrderStatusId=setOrderStatusId;
exports.setBusinessTypeId=setBusinessTypeId;
exports.searchOrder=searchOrder;
exports.getPaymentsList=getPaymentsList;
exports.getPaymentsListCallBack=getPaymentsListCallBack;
exports.getErpOrderTypesList=getErpOrderTypesList;
exports.getErpOrderTypesListCallBack=getErpOrderTypesListCallBack;
exports.getOrderstatusList=getOrderstatusList;
exports.getOrderstatusListCallBack=getOrderstatusListCallBack;
exports.loadOrderDetail=loadOrderDetail;
exports.loadOrderDetailCallBack=loadOrderDetailCallBack;
exports.processOrder=processOrder;
exports.processOrderCallBack=processOrderCallBack;
exports.toPrintOrderDetail=toPrintOrderDetail;
exports.toPrintOrderDetailCallBack=toPrintOrderDetailCallBack;
exports.showDiv=showDiv;
})
//})();
